//
//  BK_My_Cup_NoUsed_tabVCell.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/2/22.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BK_My_Cup_NoUsed_tabVCell.h"
#import "BK_my_couponCommon.h"
#import "Masonry.h"
#import "BKMyCommon.h"

@interface BK_My_Cup_NoUsed_tabVCell()

@property (nonatomic, strong) UIImageView *grayImg;
@property (nonatomic, strong) UIImageView *whiteImg;
@property (nonatomic, strong) UILabel *moneyAmountLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UIView *view_bg;
@property (nonatomic,strong) UIImageView *expireImageView;

@end
@implementation BK_My_Cup_NoUsed_tabVCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initlizeUI];
    }
    return self;
}

- (void)initlizeUI {
    
    __weak typeof (self)weakSelf = self;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = RGBCOLOR(242, 242, 242, 1);
    
    /*
     * 打底的View
     */
    self.view_bg = [[UIView alloc] init];
    self.view_bg.backgroundColor = RGBCOLOR(242, 242, 242, 1);
    [self addSubview:self.view_bg];
    [self.view_bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_top).mas_offset(10);
        make.left.equalTo (weakSelf.mas_left).mas_offset(ApplicationBackGauge);
        make.right.equalTo(weakSelf.mas_right).mas_offset(0);
        make.bottom.equalTo(weakSelf.mas_bottom).mas_offset(0);
    }];
    
    /*
     * 左边灰色图片
     */
    _grayImg = [[UIImageView alloc] init];
    [self.view_bg addSubview:_grayImg];
    [_grayImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view_bg.mas_top).mas_offset(0);
        make.left.equalTo(weakSelf.view_bg.mas_left).mas_offset(0);
        make.width.equalTo(@(100));
        make.bottom.equalTo(weakSelf.view_bg.mas_bottom).offset(-1);
    }];
    
    _moneyAmountLabel = [[UILabel alloc] init];
    _moneyAmountLabel.textColor = [UIColor whiteColor];
    _moneyAmountLabel.font = [UIFont systemFontOfSize:30];
    _moneyAmountLabel.textAlignment = NSTextAlignmentCenter;
    [self.grayImg addSubview:self.moneyAmountLabel];
    
    /*
     * 白色的图片
     */
    _whiteImg = [[UIImageView alloc] init];
    [self.view_bg addSubview:self.whiteImg];
    [self.whiteImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.grayImg.mas_right).mas_offset(0);
        make.top.equalTo(weakSelf.view_bg.mas_top).mas_offset(0);
        make.right.equalTo(weakSelf.view_bg.mas_right).mas_offset(-ApplicationBackGauge);
        make.bottom.equalTo(weakSelf.view_bg.mas_bottom).mas_offset(-1);
    }];
    
    if ([UIScreen mainScreen].bounds.size.width < 375) {
        _grayImg.image = [UIImage imageNamed:@"BK_my_couponGrayBG"];
        
        _whiteImg.image = [UIImage imageNamed:@"BK_my_couponWhiteBG"];
        
        [_moneyAmountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(weakSelf.grayImg.mas_centerX);
            make.centerY.mas_equalTo(weakSelf.grayImg.mas_centerY);
            make.width.mas_equalTo(100);
        }];
    } else {
        _grayImg.image = [UIImage imageNamed:@"BK_my_couponGrayBG"];
        _whiteImg.image = [UIImage imageNamed:@"BK_my_couponWhiteBG"];
        
        [_moneyAmountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(weakSelf.grayImg.mas_centerX);
            make.centerY.mas_equalTo(weakSelf.grayImg.mas_centerY);
            make.width.mas_equalTo(111);
        }];
    }
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:13];
    _titleLabel.textColor = BK_MY_COLOR_04;
    _titleLabel.numberOfLines = 2;
    [self.whiteImg addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.whiteImg.mas_left).offset(20);
        make.right.mas_equalTo(weakSelf.whiteImg.mas_right).offset(-10);
        make.top.mas_equalTo(weakSelf.whiteImg.mas_top).offset(15);
    }];
    
    _expireImageView = [[UIImageView alloc] init];
    [self.whiteImg addSubview:_expireImageView];
    [_expireImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.whiteImg.mas_top).offset(5);
        make.right.mas_equalTo(weakSelf.whiteImg.mas_right).offset(0);
        make.width.mas_equalTo(94);
        make.height.mas_equalTo(72);
    }];
    
    _dateLabel = [[UILabel alloc] init];
    _dateLabel.font = [UIFont systemFontOfSize:10];
    _dateLabel.textColor = BK_MY_COLOR_04;
    [self.whiteImg addSubview:_dateLabel];
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.whiteImg.mas_left).offset(20);
        make.bottom.mas_equalTo(weakSelf.whiteImg.mas_bottom).offset(-10);
    }];
}

- (void)setUsedModel:(BK_my_CouponModel *)usedModel {
    
    _usedModel = usedModel;
    NSString *string = [NSString stringWithFormat:@"￥%@",_usedModel.reduceCost];
    NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithString:string];
    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, 1)];
    // NSRange range = [string rangeOfString:@"."];
    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(string.length - 3, 3)];
    _moneyAmountLabel.attributedText = attriStr;
    _titleLabel.text = [NSString stringWithFormat:@"%@", _usedModel.couponTypeStr];
    _dateLabel.text = [NSString stringWithFormat:@"%@", _usedModel.invalidTimeStr];
    
    if ([_usedModel.status isEqualToString:@"2"]) {
        [_expireImageView setImage:[UIImage imageNamed:@"BK_my_couponUsedBG"]];
    }
    
    if ([_usedModel.status isEqualToString:@"3"]) {
        [_expireImageView setImage:[UIImage imageNamed:@"BK_my_couponOutOfDataBG"]];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
